/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */
package cn.com.ksplatform.modules.system.auth.cachemanager.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import cn.com.ksplatform.common.logger.Log;
import cn.com.ksplatform.modules.system.auth.parammanager.model.PlatParamItem;
import cn.com.ksplatform.modules.system.auth.parammanager.service.PlatParamItemService;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

/**
 * 系统字典缓存
 * ClassName:ParamCacheService.java <br/>
 * Date: 2015年12月14日<br/>
 * 
 * @author Mr.Xiao
 * @version 1.0
 */
@Component("system.modules.system.cache.ParamCacheService")
public class ParamCacheService {
	@Autowired
	@Qualifier("cacheManagerFactory")
	CacheManager cacheManager;
	
	Cache paramCache = null;
	
	public Cache getCache(){
		if(paramCache == null){
			paramCache = cacheManager.getCache("ParamCache");
		}
		return paramCache;
	}
	
	@Autowired
	PlatParamItemService platParamItemService;
	
	public void init(){
		List<PlatParamItem> list = (List<PlatParamItem>)platParamItemService.getAllParamItem();
		for(PlatParamItem pdi : list){
			String key = pdi.getEkey();
			Element em = new Element(key, pdi);
			getCache().put(em);
		}
		Log.info("初始化系统参数缓存数量:"+list.size());
	}
}
